using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using InfoJetSoft.Service;


namespace InfoJetServiceDemo
{
    public partial class xdoc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        // *** Please reference http://www.infojetsoft.com/service_faq.htm for more information.

        protected override void Render(HtmlTextWriter output)
        {
            string publishUrl = this.Context.Request["xdoc_param_xsn_uri"];
            if (publishUrl != null && publishUrl.Length > 0)
            {
                if (InfoJetService.IsFormSessionDataLost(this.Context))
                {
                    if (InfoJetSoft.Service.Util.ConfigUtil.UseAJAX())
                    {
                        output.Write("window.location = 'Default.aspx';");
                    }
                    else
                    {
                        output.Write("<script language='javascript'>");
                        output.Write("parent.window.location = 'Default.aspx';");
                        output.Write("</script>");
                    }
                    output.Close();
                    return;
                }
                if (!InfoJetService.ContainsXSN(publishUrl))
                {
                    //Try to load the binary content of the form template by the publishUrl.
                    //Then please call InfoJetService.Register().
                }
            }

            try
            {
                InfoJetForm form = InfoJetService.UpdateForm(this.Context);
                output.Write(form.Xhtml);
                output.Close();
            }
            catch (Exception e)
            {
                output.Write(e.Message + "<br>");
                output.Write(e.StackTrace);
                output.Close();
            }
        }
    }
}
